﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using zk312.BLL;
using zk312.MODEL;

namespace zk312.UI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoomController : ControllerBase
    {
        public Roombll Roombll { get; }

        public RoomController(Roombll roombll)
        {
            Roombll = roombll;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        [HttpPost("AddRoom")]
        public int AddRoom(Room room)
        {
            try
            {
                return Roombll.AddRoom(room);
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet("GetRoom")]
        public dynamic GetRoom(int index, int size, string? name, string? type)
        {
            try
            {
                return Roombll.GetRoom(index, size, name, type);
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 逻辑删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("DelRoom")]
        public dynamic DelRoom(int id)
        {
            try
            {
                return Roombll.DelRoom(id);
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 修改第一步 先查
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("Getid")]
        public dynamic Getid(int id)
        {
            try
            {
                return Roombll.Getid(id);
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 修改第二部 修改
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        [HttpPut("UpdRoom")]
        public dynamic UpdRoom(Room room)
        {
            try
            {
                return Roombll.UpdRoom(room);
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
